 
      var  searcpageNo= 1;  
    layui.use(['icheck','element',"laytpl",'laypage','form','laydate'], function() {
        var $ = layui.jquery,
        layer = layui.layer,
        laytpl = layui.laytpl,
        laypage = layui.laypage;
        var form = layui.form();
        var tjstate =0;
      
       
        
     
	    form.render(); 
	    
	    var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	
    	//分页按钮
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#customerlistform").submit();
                }
            }
        }); 
    	
 
    	  
     
    	$(".searchbtnclean").on("click",function(){
    		$("#keyWord").val("");
    		$("#province").val("");
    		$("#address").val("");
    		$("#city").html("<option value=\"\">请选择市</option>");
		    $("#city").val("");
		    $("#category").val("");
		    $("#zizhiType").val("");
    	});
    	 
 
        //点击搜索
    	$(".customersearchbtn").on("click",function(){
    		var ky = $.trim($("#keyWord").val());
       	    $("#keyWord").val(ky);
       	    $("#skipToPage").val(1);
    		$(".customersearcheform").submit();
    	});
    	
    	 
    	
    	
    	   //删除跟进记录
    	$(".scbtn").on("click",function(){
    		   var id =  $(this).attr("data");
    		   layer.confirm('确定解聘该人员？', function(index){
    			   layer.close(index);
    			   $.ajax({
                		type : "post",
                		url : "/customer/delqualificationuser",
                		data : {id:id},
                		dataType : "json",
                		success : function(data){
                			if (data == 1) {
                				layer.msg("解聘成功",{icon: 1,shade:0.1,time:2000},function(){
                					window.location.reload();
                				});
                			} else { 
                				layer.msg("解聘失败",{icon: 2,shade:0.1,time:2000});
                			}
                		}
                	});
    		   }); 
    	});
    	   //添加人员
    	$(".tjrybtn").on("click",function(){
    		   zspop = layer.open({
              		title:'聘用人员',
              	 	type:1,
              	 	id:"tjzs",
                 	  //	shadeClose: true,
                 	  	content:$('#TM-layui-zhengshu'),
                      btnAlign:'c',
                      area:['90%','95%'],
		    		   cancel: function(index, layero){ 
		    			     window.location.reload();
		    			 }   
                 	}); 
    	});
    	
   	 getZsUser = function (o){
		 var result ="";
		  var values = o;
			$.ajax({
    			type : "post",
    			url : "/customer/qualificationusers",
    			data : values,
    			async:false,
    			dataType : "json",
    			success : function(data){
    				result = data;
    			}
    		});
	  	 return result
	 }
    	
   	 $(document).on("click",".zscleanbtn",function(){
 		$("#zskeyword").val("");
 		$("#seluid").val("");
 		$("#selstate").val("");
 		  form.render(); 
   	})
 	
    
    	//证书搜索
    	$(".zssearchbtn").on("click",function(){
    			var kd =  $.trim($("#zskeyword").val());
    			$("#skpg").val(1);
    			$("#zskeyword").val(kd);
    		    var values = $("#zssearch").serialize()
    			var result = getZsUser(values);
    		    var getTpl = $("#zslb").html();
    		    
    		    if(result.resultList==null||result.resultList.length<1){
    		    	layer.msg("暂无内容",{icon: 0});
    		    	return false;
    		    }
    		    
				 laytpl(getTpl).render(result, function(html){
				 $(".tb_customerzs").html(html);
					  //view.innerHTML = html;
				 });
				  laypage({
                      cont: 'zspage',
                      curr: 1//'${pager.pageNo}'
                      ,pages: result.totalPages//'${pager.totalPages}' //总页数
                      ,
                      groups: 5 //连续显示分页数
                      ,
                      skip: true,
                      jump: function(obj, first) {
                          //得到了当前页，用于向服务端请求对应数据
                          var curr = obj.curr;
                          searcpageNo = curr;
                          if(!first) {
                        	  $("#skpg").val(curr);
                        	   values = $("#zssearch").serialize()
                  			   result = getZsUser(values); 
                        	   var getTpl = $("#zslb").html();
                        	   laytpl(getTpl).render(result, function(html){ 
                					 $(".tb_customerzs").html(html); 
                			    }); 
                          }
                      }
                  });  
    	 
    	})
    	
    	
   //人员添加
   	 $(document).on('click','.addzs',function(){
   		   
   		  var result = eval('(' + $(this).attr("data") + ')');
   	      var cusid =  $("#cusid").val();
   	      var contractid =   $("#contractid").val();
	   	   $.ajax({
		   		type : "post",
		   		url : "/customer/savecusstomerqualificationuser",
		   		data : {uid:result.id,cusid:cusid,contractid:contractid},
		   		dataType : "json",
		   		success : function(data){
		   			if (data == 1) {
		   				layer.msg("聘用成功",{icon: 1,shade:0.1,time:2000},function(){
		   					$("#skpg").val(searcpageNo);
     			    	   values = $("#zssearch").serialize()
     					   result = getZsUser(values); 
     			    	   var getTpl = $("#zslb").html();
     			    	   laytpl(getTpl).render(result, function(html){ 
     							 $(".tb_customerzs").html(html); 
     					    });  
		   				});
		   			} else { 
		   				layer.msg("聘用失败",{icon: 2,shade:0.1,time:2000});
		   			}
		   		}
		   	});
   		 
   	 });
   	 
   	 
     //人员解聘
   	 $(document).on('click','.jpbtn',function(){
   		 
	 
	    
	 
   		 
   		   
	      var id =  $(this).attr("data");
		   layer.confirm('确定解聘该人员？', function(index){
			   layer.close(index);
			   $.ajax({
	        		type : "post",
	        		url : "/customer/delqualificationuser",
	        		data : {id:id},
	        		dataType : "json",
	        		success : function(data){
	        			if (data == 1) {
	        				layer.msg("解聘成功",{icon: 1,shade:0.1,time:2000},function(){
	        				   	   $("#skpg").val(searcpageNo);
	        			    	   values = $("#zssearch").serialize()
	        					   result = getZsUser(values); 
	        			    	   var getTpl = $("#zslb").html();
	        			    	   laytpl(getTpl).render(result, function(html){ 
	        							 $(".tb_customerzs").html(html); 
	        					    });  
	        					     window.location.reload();
	        				});
	        			} else { 
	        				layer.msg("解聘失败",{icon: 2,shade:0.1,time:2000});
	        			}
	        		}
	        	});
		   });  
   		 
   	 });
    	
    
    });
	
 
 
